/*
 * <p>Copyright® 2009-2022 东软 IT 实训中心版权所有。</p>
 */

package com.max.back.doctor.service.impl;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.max.back.doctor.dao.ExaminationDao;
import com.max.back.doctor.service.ExaminationService;
import com.max.back.entity.Examination;
import org.springframework.stereotype.Service;

/**
 * @author 辛凤文 forward.seen@foxmail.com
 * @version 1.0
 * @description <p>
 * <code>ExaminationServiceImpl</code>
 *
 * </p>
 * @time 2022/7/25 15:03
 * @see
 */
@Service
public class ExaminationServiceImpl extends ServiceImpl<ExaminationDao,
        Examination> implements ExaminationService {
    @Override
    public String createAndGetExaminationId(String patientHistoryId) {
        // 判断是否有该检查项
        Examination examination = getOne(new QueryWrapper<Examination>().eq("patient_History_Id",
                patientHistoryId));
        if (examination != null) {
            // 有的话直接返回ID
            return examination.getId();
        }
        //TODO 没有创建并返回ID
        examination = new Examination();
        String examinationId = IdUtil.simpleUUID();
        examination.setId(examinationId);
        examination.setPatientHistoryId(patientHistoryId);
        examination.setDeleted(false);
        save(examination);
        return examinationId;
    }
}